import Vue from 'vue'
import Vuex from 'vuex'
// import mutations from './mutations.js'

Vue.use(Vuex)
import msgList from './msgList'
import msgCont from './msgCont'
import jsMsg from './jsMsg'
const state = {
  currentCompany: {},
  phone: wx.getStorageSync('phone') || '',
  unreadNum: 0, // 详情页面中的未读消息数量
  /* name: 'HD384483939',// 用户名
   infocount: 1,// 消息数量
   token: '123456'//token*/
};
const mutations = {
  SET_CURRENT_COMPANY(state, data) {
    state.currentCompany = data;
  },
  SET_PHONE(state, data){
    state.phone = data;
  },
  SET_UNREAD_NUM(state, data){
    state.unreadNum = data;
  },
};

const actions = {
  setCurrentCompany({commit}, data) {
    commit('SET_CURRENT_COMPANY', data)
  },
  setPhone({commit}, data){
    commit('SET_PHONE', data);
  },
  setUnreadNum({commit}, data){
    commit('SET_UNREAD_NUM', data);
  },
};

export default new Vuex.Store({
  state,
  mutations,
  actions,
  modules:{
    msgList,
    msgCont,
    jsMsg,
  },
  getters:{
    currentCompany: state => state.currentCompany,
    selfPhone: state=> state.phone,
    msglist: state => state.msgList.msglist,
    msgCont:state=>state.msgCont.msgCont,
    changePosition:state=>state.msgCont.status,
    unreadNum: state => state.unreadNum,
  },
  /* plugins: [
       createPersistedState({
           storage: {
               getItem: key => {
                   wx.getStorageSync(key)
               },
               setItem : (key ,value)=>{
                   wx.setStorageSync(key,value)
               },
               removeItem:key=>{
                   wx.clearStorage()
               }
           }
       })
   ]*/
})

